package com.only.test;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import com.onlyxiahui.app.base.AppContext;
import com.onlyxiahui.app.base.ObjectFactory;

/**
 * date 2017-12-27 10:16:47
 * @author XiaHui
 */
public class ConcurrentHashMapTest1 {

	public static void main(String[] arg) {
		int count = 20;
		final AppContext ac = new AppContext();
		final ObjectFactory objectFactory = new ObjectFactory(ac);
		ExecutorService pool = new ThreadPoolExecutor(
				count,
				count,
				0L,
				TimeUnit.MILLISECONDS,
				new LinkedBlockingQueue<Runnable>());
		final long time = System.currentTimeMillis();
		System.out.println(time);
		for (int i = 0; i < count; i++) {
			pool.execute(new Runnable() {

				@Override
				public void run() {
					for (int i = 0; i < 100; i++) {
						UserDataBox udm = objectFactory.getObject(i + "", UserDataBox.class);
						// Object ud = ac.getService(TestService.class);
						System.out.println(udm + ":" + i);
						// System.out.println(ud + ":" + i);
						System.out.println(System.currentTimeMillis() - time);

						new Thread() {
							public void run() {
								for (int i = 0; i < 100; i++) {
									UserDataBox udm = objectFactory.getObject(i + "", UserDataBox.class);
									// Object ud =
									// ac.getService(TestService.class);
									System.out.println(udm + ":" + i);
									// System.out.println(ud + ":" + i);
									System.out.println(System.currentTimeMillis() - time);
								}
							}
						}.start();
					}
				}
			});
		}
	}
}
